import { Component, OnInit } from '@angular/core';
import {Globals} from "../../../globals";
import {PageHelper} from "../../../utils/page-helper-model";
import {RoleIdEnum} from "../../../enums/role-id.enum";
import {BaseService} from "../../../shared/service/base.service";
import {ActivatedRoute} from "@angular/router";
import {Consts} from "../../../config/consts";
import {ApiUrl} from "../../../config/api-url";
import {MyDateModel} from "../../../models/my-date.model";

@Component({
  selector: 'app-net-cart-recharge-statistic',
  templateUrl: './net-cart-recharge-statistic.component.html',
  styleUrls: ['./net-cart-recharge-statistic.component.less']
})
export class NetCartRechargeStatisticComponent implements OnInit {
  isMobile = Globals.isMobile();
  // 分页
  pageHelper: PageHelper = new PageHelper;

  listOfData: any;
  // 开始日期类型
  startDateTimeType = 'start';
  // 结束日期类型
  endDateTimeType = 'end';
  // 开始日期
  startDateTime: Date;
  // 结束日期
  endDateTime: Date;
  isCollapse = true;
  // 日月数据统计按钮样式
  day = 'primary';
  month = 'default';
  type = 1;
  userInfo: any;

  roleIdEnum = {
    SUPER_ADMINISTRATOR: RoleIdEnum.SUPER_ADMINISTRATOR,
  };

  constructor(private baseService: BaseService, private activatedRoute: ActivatedRoute) {

  }

  ngOnInit(): void {
    this.startDateTime = this.baseService.zorro.getDateTime().startLastMonth;
    this.endDateTime = this.baseService.zorro.getDateTime().endLastMonth;
    this.findData();
  }

  findData() {
    const body = {
      createTime: this.startDateTime,
      updateTime: this.endDateTime
    };
    this.baseService.findListByMuchCondition(ApiUrl.StatsNetCardRechargeUrl + '/findList', body, this.pageHelper).subscribe(
      data => {
        if (data.status == 0) {
          this.pageHelper.totalItems = data.data.total;
          this.listOfData = data.data.list;
        } else {
          this.baseService.layer.messageError(data.msg);
        }
      }
    );
  }

  // 将开始、结束时间往外抛
  outDateTime($event: MyDateModel) {
    /**
     * date: Fri Mar 19 2021 23:59:06 GMT+0800 (中国标准时间) {}
     * type: "end"
     */
    if ($event.type == 'start') {
      this.startDateTime = $event.date;
    } else if ($event.type == 'end') {
      this.endDateTime = $event.date;
    }
  }

  onStartMonth($event) {
    this.startDateTime = $event;
  }

  onEndMonth($event: any) {
    this.endDateTime = $event;
  }

  search() {
    this.pageHelper.currentPage = 1;
    this.findData();
  }


  nzPageIndexChange($event: number) {
    this.pageHelper.currentPage = $event;
    this.findData();
  }
}
